<!-- subpkg_consult/department/index.vue -->
<script lang="ts" setup>
  import { departmentListApi } from '@/apis/consult'
  import type { DepartData } from '@/types/consult'

  import { computed, ref } from 'vue'

  // 1. 科室列表
  const departmentList = ref<DepartData[]>([])
  // 2. 切换选中
  const activeIndex = ref(0)
  // 3. 参数传递
  defineProps<{
    type: string
    illnessType: string
  }>()
  const childList = computed(() => {
    return departmentList.value[activeIndex.value]?.child
  })
  const gitList = async () => {
    const res = await departmentListApi()
    // 渲染列表数据
    departmentList.value = res
    console.log(res)
  }
  gitList()
</script>

<template>
  <view class="department-page">
    <scroll-view scroll-y class="department-primary">
      <!-- 一级科室 -->
      <view
        v-for="(item, index) in departmentList"
        :key="item.id"
        class="department-item"
        @click="activeIndex = index"
        :class="{ active: activeIndex === index }"
      >
        {{ item.name }}
      </view>
      <view class="department-item"></view>
    </scroll-view>
    <scroll-view class="department-secondary">
      <!-- 二级科室 -->
      <navigator
        hover-class="none"
        url="/subpkg_consult/description/index?type=${type}&illnessType=${illnessType}&depId=${childDepartment.id}"
        class="department-item"
        v-for="item in childList"
        :key="item.id"
      >
        {{ item.name }}
      </navigator>
    </scroll-view>
  </view>
</template>

<style lang="scss">
  @import './index.scss';
</style>
